<template>
  <div v-if="$route.meta.needNav" style="padding: 0px;">
    <navBarComponents />
    <!-- <router-view :key="$route.fullPath" /> -->
    <router-view v-slot="{ Component }">
      <keep-alive>
        <component :is="Component" :key="$route.fullPath" />
      </keep-alive>
    </router-view>
    <footerComponents />
  </div>
  <div v-if="$route.meta.needAdminNav">
    <el-container>
      <el-aside style="width: auto;">
        <navComponents />
      </el-aside>
      <el-main style="padding: 0px;height: 100vh;">
        <router-view :key="$route.fullPath" />
        <!-- <router-view v-slot="{ Component }">
          <keep-alive>
            <component :is="Component" :key="$route.fullPath" />
          </keep-alive>
        </router-view> -->
      </el-main>
    </el-container>
  </div>
  <div v-if="!$route.meta.needNav && !$route.meta.needAdminNav" style="padding: 0px;">
    <router-view :key="$route.fullPath" />
  </div>
</template>
<script >
import { useRoute } from 'vue-router';
import navBarComponents from './components/global/navBarComponents.vue';
import footerComponents from './components/global/footerComponents.vue';
import navComponents from './components/background/global/navComponents.vue';
import { useStore } from 'vuex';
import $ from 'jquery';
import { reactive } from 'vue';
export default {
  components: {
    navBarComponents,
    footerComponents,
    navComponents,
  },
  setup() {
    let route = useRoute();
    const store = useStore();
    if (localStorage.getItem("isLogin")) {//token验证
      console.log(localStorage.getItem("token") + "获取到的TOKEN");
      $.ajax({
        url: "http://124.221.73.180:3001/adminInfo/loginCheck/",
        type: "post",
        cache: false,
        async: false,
        headers: {
          "satoken": localStorage.getItem("token")
        },
        success(resp) {
          if (resp == "success") {
            let data = reactive({
              token: localStorage.getItem("token"),
            })
            store.dispatch("login", data);
          }
        }
      })
    }
    return {
      route,
    }
  }
}
</script>
<style>
body {
  margin: 0px;
  background-color: rgb(247, 248, 250);
  font-family: "微软雅黑", "宋体", serif;
}
</style>
